'use strict';

angular.module('myApp.teach_cat', [])

.controller('teach_catCtrl', ['$scope','$http',
    function($scope,$http) {

    $http.get('v1/teach_content_cat').success(function(data){
        $scope.models = data.result;
          console.log($scope.model);
    });

    $scope.create_cat = function(){
    	var value = {'name':$('#create_cat').val()};
        $http.post('v1/teach_content_cat',value).success(function(data){
            if( !data.error ){
                alert("新增成功","success");
			    $http.get('v1/teach_content_cat').success(function(data){
			        $scope.models = data.result;
			          console.log($scope.model);
			    });          
            }else{
                alert(data.message);
            }
        });
    };
	
	$scope.del = function(model){
		    $http.delete('v1/teach_content_cat/'+model.id).success(function(data){
		     	console.log(model.id);
				if( !data.error ){
					$scope.models.splice($scope.models.indexOf(model),1);
					alert("删除成功");
				}else{
					alert(data.message);
				}
		    });
    	
	    };

}]);